﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:Core="clr-namespace:LaunchMeNot.Core;assembly=LaunchMeNot.Core"
    xmlns:conv="clr-namespace:LaunchMeNot.Converters">
    <SolidColorBrush x:Key="DisabledForeground" Color="LightGray"/>
    <Style x:Key="{x:Type TextBlock}" TargetType="{x:Type TextBlock}">
        <Setter Property="OverridesDefaultStyle" Value="False"/>
        <Setter Property="TextTrimming" Value="CharacterEllipsis"/>
        <Setter Property="TextWrapping" Value="Wrap"/>
        <Style.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="{StaticResource DisabledForeground}"/>
            </Trigger>
        </Style.Triggers>
    </Style>
    
    <Style x:Key="TimerStyle" TargetType="{x:Type TextBlock}">
        <Setter Property="FontSize" Value="30"/>
        <Setter Property="FontWeight" Value="Bold"/>
    </Style>
    
    <DataTemplate x:Key="PendingEntryTemplate" DataType="{x:Type Core:PendingLaunchMeNotEntry}">
        <DataTemplate.Resources>
            <conv:EntryStatusConverter x:Key="entryStatusConverter"/>
            <conv:BooleanInverter x:Key="BooleanInverter"/>
            <conv:CountdownFormatConverter x:Key="CountdownFormatConverter"/>
        </DataTemplate.Resources>
        <Grid Margin="6,2,6,2" IsEnabled="{Binding IsLaunched,Converter={StaticResource BooleanInverter}}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            
            <Image Grid.Column="0" Width="16" Height="16" VerticalAlignment="Center" Margin="0,0,10,0">
                <Image.Source>
                    <MultiBinding Converter="{StaticResource entryStatusConverter}">
                        <Binding Path="LaunchDelay"/>
                        <Binding Path="LaunchDelayRemaining"/>
                        <Binding Path="IsLaunched"/>
                        <Binding Path="ErrorMessage"/>
                    </MultiBinding>
                </Image.Source>
            </Image>
            <TextBlock Grid.Column="1" Text="{Binding Name}" TextTrimming="CharacterEllipsis" TextWrapping="Wrap" HorizontalAlignment="Stretch" />
            <TextBlock Grid.Column="2" TextAlignment="Right">
                <TextBlock.Text>
                    <MultiBinding Converter="{StaticResource CountdownFormatConverter}">
                        <Binding Path="LaunchDelay"/>
                        <Binding Path="LaunchDelayRemaining"/>
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
            <ScrollViewer Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" x:Name="scrError" Margin="0,1,0,0" MinHeight="0" MaxHeight="100" CanContentScroll="True"  HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
                <TextBox x:Name="txtError"  MaxWidth="{Binding RelativeSource={RelativeSource AncestorType={x:Type ScrollViewer}},Path=ViewportWidth}" 
                         Text="{Binding ErrorMessage}" 
                         ScrollViewer.CanContentScroll="False" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Disabled" Style="{StaticResource SelectableTextBlock}"/>
            </ScrollViewer>
        </Grid>
        <DataTemplate.Triggers>
            <Trigger Property="Text" Value="" SourceName="txtError">
                <Setter Property="Visibility" Value="Collapsed" TargetName="scrError"/>
            </Trigger>
        </DataTemplate.Triggers>
    </DataTemplate>
    
    <Style x:Key="PendingLaunchList" TargetType="{x:Type ListBox}" BasedOn="{StaticResource {x:Type ListBox}}">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderBrush" Value="Transparent"/>
        <Setter Property="ItemTemplate" Value="{StaticResource PendingEntryTemplate}"/>
        <Setter Property="ItemContainerStyle">
            <Setter.Value>
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                <ContentPresenter/>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>